package com.ruoyi.common.core.domain;

import com.alibaba.fastjson2.JSONArray;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author tianl
 * @date 2023/5/6
 * @description: 为了解决全局typeHandler将数组转为list
 * 因typeHandler无法区分List<Long>和List<String>
 */
public class DbArray extends JSONArray implements Serializable {

    public List<Long> toLong() {
        return toJavaList(Long.class);
    }

    public List<Integer> toInt() {
        return toJavaList(Integer.class);
    }

    public List<String> toStr() {
        return toJavaList(String.class);
    }

    public DbArray(List<?> list) {
        super();
        addAll(list);
    }

    public DbArray(Set<?> list) {
        super();
        addAll(new ArrayList<>(list));
    }

    public DbArray() {
        super();
    }

    public DbArray(String data) {
        super(JSONArray.parseArray(data));
    }
}
